﻿using System.Data;
using _10_HPBar.Tool;

namespace _10_HPBar
{
    internal class HPBar
    {
        int hp, maxHp;
        int x,y;

        public HPBar(int x,int y,int maxHp)
        {
            this.x = x;
            this.y = y;
            this.hp = maxHp;
            this.maxHp = maxHp;
        }

        public void SetHp(int hp)
        {
            this.hp = hp;
            if (this.hp > maxHp)
            {
                this.hp = maxHp;
            }
            if (this.hp < 0)
            {
                this.hp = 0;
            }
            Clear();
            Render();
        }

        public void Clear()
        {
            for (int i = 0; i < 10; i++)
            {
                Utility.MyPrint("  ", x + 2 + i, y);
            }
        }

        public void Render()
        {
            Utility.MyPrint("HP: ", x, y);
            for (int i = 0; i < hp * 10 / maxHp; i++)
            {
                Utility.MyPrint("■",x + 1 + i,y,ConsoleColor.Red);
            }
            
        }
    }
}
